package gradle.common.core.config.task;

import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.stereotype.Component;

/**
 * 配置定时任务的线程池
 * 防止线程异常捕获不到
 */
@ConditionalOnBean(ThreadPoolTaskScheduler.class)
@Component
public class ScheduledTaskCronConfig implements SchedulingConfigurer {

    @Resource
    private ThreadPoolTaskScheduler taskExecutor;

    /**
     * 定时任务
     *
     * @param taskRegistrar the registrar to be configured.
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

        taskRegistrar.setScheduler(taskExecutor);
    }
}